package com.jinkaimen.kqb.ui.activity;

import android.content.Intent;
import android.os.Message;
import android.text.TextUtils;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.ht.baselibs.ui.base.BaseActivity;

import com.ht.baselibs.ui.widget.jsbridge.BridgeHandler;
import com.ht.baselibs.ui.widget.jsbridge.BridgeWebView;
import com.ht.baselibs.ui.widget.jsbridge.CallBackFunction;
import com.ht.baselibs.utils.UIUtils;
import com.jinkaimen.kqb.R;


public class WebViewNotifyActivity extends BaseActivity {
    private BridgeWebView mWebView;
    private String mUrl;
    private String mCenterTitle;

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initTitleBar() {
        if (!TextUtils.isEmpty(mCenterTitle)) {
            mTitleBarView.setTitleText(mCenterTitle);
        } else {
            mTitleBarView.setTitleText("钱包++");
        }
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        mUrl = callIntent.getStringExtra("url");
        mCenterTitle = callIntent.getStringExtra("title");
    }

    @Override
    protected int initContentView() {
        return R.layout.activity_web_view;
    }

    @Override
    protected void initChildView() {
        mWebView = (BridgeWebView) findViewById(R.id.web_view);
        WebSettings settings = mWebView.getSettings();
        mWebView.setVerticalScrollBarEnabled(false);
        mWebView.setHorizontalScrollBarEnabled(false);
        settings.setJavaScriptEnabled(true);
        settings.setDomStorageEnabled(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
//        settings.setUseWideViewPort(true);
//        settings.setLoadWithOverviewMode(true);
//        mWebView.getSettings().setBlockNetworkImage(false);
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
//                web_view.loadUrl("http://hsy.qianbaojiajia.com/notice/detail?noticeId=49");
                return true;
            }
        });
        mWebView.registerHandler("getVersionName", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                function.onCallBack("回调数据----哈哈");
            }
        });
    }


    @Override
    protected void initChildData() {
        mWebView.loadUrl("file:///android_asset/demo.html");


    }

    @Override
    protected void setChildViewListener() {

    }

    protected void handleMessage(BaseActivity context, Message msg) {
        mWebView.callHandler("getVersionName", msg.toString(), new CallBackFunction() {
            @Override
            public void onCallBack(String data) {
                UIUtils.showToast("调用成功");
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
}

